package com.xiaobai.zhuangxiuguanjia.model;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gggcccwww on 2015/6/16.
 */
public class Company {
    private String action;
    private int allRows;
    private int errorCode;
    private String version;
    private List<Data> dataList;

    public String getAction() {
        return action;
    }

    public void setAction(String action) {
        this.action = action;
    }

    public int getAllRows() {
        return allRows;
    }

    public void setAllRows(int allRows) {
        this.allRows = allRows;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(int errorCode) {
        this.errorCode = errorCode;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public List<Data> getDataList() {
        return dataList;
    }

    public void setDataList(List<Data> dataList) {
        this.dataList = dataList;
    }

    public void parseJSON(JSONObject json){
        if (json != null) {
            try {
                action=json.getString("action");
                version=json.getString("version");
                errorCode=json.getInt("errorCode");
                allRows=json.getInt("allRows");
                JSONArray dataJsonArray = json.getJSONArray("data");
                int length = dataJsonArray.length();
                if(length>0){
                    dataList=new ArrayList<Data>();
                    for (int i = 0; i < length; i++) {
                        JSONObject dataJsonObject = dataJsonArray.getJSONObject(i);
                        Data data = new Data();
                        data.parseJSON(dataJsonObject);
                        dataList.add(data);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public String toString() {
        return "Company{" +
                "action='" + action + '\'' +
                ", allRows=" + allRows +
                ", errorCode=" + errorCode +
                ", version='" + version + '\'' +
                ", dataList=" + dataList +
                '}';
    }
}
